<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';

$return['diy']=$this->plugin_setting('diy');
$basic=$this->plugin_setting('basic');
$return['banner']=$basic['image'];
if($_RQ['op']=='main'){
	//查询所有未锁定服务员工
	$worker_list=pdo_getall('jy_meiye_worker',array('uniacid'=>$_SESSION['uniacid'],'islock'=>'0','status'=>'1'));
	if($worker_list){
		foreach($worker_list as &$item){
			$item['lev_name']=pdo_getcolumn('jy_meiye_lev',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['lev']),'lev_name');
		    //已支付，已确认，已完成订单数
			$num1=pdo_count('jy_meiye_order',array('uniacid'=>$_SESSION['uniacid'],'worker_id'=>$item['id'],'status'=>'1'));
			$num2=pdo_count('jy_meiye_order',array('uniacid'=>$_SESSION['uniacid'],'worker_id'=>$item['id'],'status'=>'2'));
			$num3=pdo_count('jy_meiye_order',array('uniacid'=>$_SESSION['uniacid'],'worker_id'=>$item['id'],'status'=>'4'));
			$item['num']=$num1+$num2+$num3;
		}
	}
	$return['post']=array();
	$return['worker_list']=$worker_list;
	exi($return);
}
if($_RQ['op']=='list'){

	exi($return);
}
if($_RQ['op']=='detail'){
	if(!$_RQ['id']){
		exi('没有找到该员工，请重新选择！','error','jy_meiye/worker/main');
	}
	//查询该员工具体信息
	$worker=pdo_get('jy_meiye_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	//等级名称
	$lev_name=pdo_getcolumn('jy_meiye_lev',array('uniacid'=>$_SESSION['uniacid'],'id'=>$worker['lev_id']),'lev_name');
	//日期 今天，未来七天
	$data=array();
	$data['0']['riqi']=date("m-d",time("day")); 
	$data['1']['riqi']=date("m-d",strtotime("+1 day")); 
	$data['2']['riqi']=date("m-d",strtotime("+2 day")); 
	$data['3']['riqi']=date("m-d",strtotime("+3 day")); 
	$data['4']['riqi']=date("m-d",strtotime("+4 day")); 
	$data['5']['riqi']=date("m-d",strtotime("+5 day")); 
	$data['6']['riqi']=date("m-d",strtotime("+6 day")); 
	$weekarray=array("日","一","二","三","四","五","六"); //先定义一个数组
	$data['0']['xinq']= "星期".$weekarray[date("w")];
	$data['1']['xinq']= "星期".$weekarray[date("w",strtotime(date("Y-m-d",strtotime("+1 day"))))];
	$data['2']['xinq']= "星期".$weekarray[date("w",strtotime(date("Y-m-d",strtotime("+2 day"))))];
	$data['3']['xinq']= "星期".$weekarray[date("w",strtotime(date("Y-m-d",strtotime("+3 day"))))];
	$data['4']['xinq']= "星期".$weekarray[date("w",strtotime(date("Y-m-d",strtotime("+4 day"))))];
	$data['5']['xinq']= "星期".$weekarray[date("w",strtotime(date("Y-m-d",strtotime("+5 day"))))];
	$data['6']['xinq']= "星期".$weekarray[date("w",strtotime(date("Y-m-d",strtotime("+6 day"))))];
	//可服务项目
	$services=explode(";",$worker['service']);
	$services=array_filter($services);
	$service=array();
	foreach($services as &$item){
		$item=pdo_get('jy_meiye_serve',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item));	
		$item['package']=json_decode($item['package'],true);
		if($item['status']==1){
			array_push($service,$item);
		}
		
	}
	$return['worker']=$worker;
	$return['service']=$service;
	$return['data']=$data;
	$return['post']=array();
	$this->session('worker_id',$_RQ['id']);
	exi($return);
}
if($_RQ['op']=='notice'){
	//日期 今天，未来七天
	$data=array();
	$data['0']=date("Y-m-d",time("day")); 
	$data['1']=date("Y-m-d",strtotime("+1 day")); 
	$data['2']=date("Y-m-d",strtotime("+2 day")); 
	$data['3']=date("Y-m-d",strtotime("+3 day")); 
	$data['4']=date("Y-m-d",strtotime("+4 day")); 
	$data['5']=date("Y-m-d",strtotime("+5 day")); 
	$data['6']=date("Y-m-d",strtotime("+6 day"));
    $post=get_postdata();

		if($post){
		//$package=ijson_encode(array('package_title'=>$post['package_title'],'package_price'=>$post['package_price']));
		//$time=ijson_encode(array('data'=>$post['data'],'start'=>$post['start'],'end'=>$post['end']));
		$package=pdo_getcolumn('jy_meiye_serve',array('uniacid'=>$_SESSION['uniacid'],'id'=>$post['serve_id']),'package');
		$package=json_decode($package,true);
		$insert=array(
		'uniacid'=>$_SESSION['uniacid'],
		'user_id'=>$_SESSION['uid'],
		'serve_id'=>$post['serve_id'],
		'worker_id'=>$this->session('worker_id'),
		'package'=>ijson_encode($package[$post['packageid']]),
		'serve_time'=>$time,
		'timeid'=>$post['timeid'],
		'day'=>$data[$post['dayid']],
		'ordersn'=>get_ordersn('jy_meiye_order','ordersn'),
		'createtime'=>TIMESTAMP,
	);
	pdo_insert('jy_meiye_order',$insert);
	$id=pdo_insertid();
		}	
	exi('','','jy_meiye/book/main/id='.$id);
}